const md5=require("md5")
const jwt=require("jsonwebtoken")
const {TOKEN_KEY}=require("../config/index")
const svg=require("svg-captcha")

const createCode=()=>{
    const data={
        size:4,
        noise:1,
        color:true
    }
    return svg.create(data)
}

const createToken=id=>{
    const data={
        id,
        iss:"1907c",
        exp:+new Date()+2*60*60*1000
    }
    return jwt.sign(data,TOKEN_KEY)
}

const createId=username=>{
    const data=JSON.stringify({
        username,
        iss:"1907C",
        time:+new Date()
    })
    return md5(data)
}

module.exports={
    createId,
    createToken,
    createCode
}